<template>
  <!-- 系统设置页面 -->
  <el-card>
    <el-form :v-model="setFrom" label-width="200px">
      <el-form-item label="人脸识别等待登录秒数">
        <el-input-number v-model="setFrom.faceRecognitionSeconds" :min="1" :max="5" style="width: 80px;"
          @change="handleChange" />秒
          <el-tooltip  content="精确到秒" placement="top" >
          <el-icon style="color:rgb(249, 202, 140); margin-left: 10px;" size="22px"><Warning /></el-icon>
        </el-tooltip>
        <span
          style="position: absolute; top: -19px; right: -45px; display: table-cell; white-space: nowrap; padding: 7px 10px; ">
          <!-- append-to=".common-table" -->
          <!-- <el-tooltip placement="top" >
            <template slot="title">
              <span>精确到秒</span>
            </template>
            <el-icon style="color:rgb(249, 202, 140);"><Warning /></el-icon>
          </el-tooltip> -->
          
        </span>
      </el-form-item>
      <el-form-item label="退出登录等待秒数">
        <el-input-number v-model="setFrom.logoutSeconds" :min="1" :max="15" :precision="0" style="width: 80px;"
          @change="handleChange" />秒
      </el-form-item>
      <el-form-item label="无人息屏等待秒数">
        <el-input-number v-model="setFrom.unmannedScreenSeconds" :min="1" :max="3600" style="width: 80px;"
          @change="handleChange" />秒
      </el-form-item>
      <!-- <el-form-item label="管理考勤应用">
        <el-select v-model="setFrom.attendance" placeholder="请选择">
          <el-option v-for="item in optionAttendance" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="考勤功能开关">
        <el-switch v-model="setFrom.switchValue" />
      </el-form-item> -->
      <el-form-item>
        <el-button @click="submitSave">保存</el-button>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<script setup>
import { onMounted, ref } from "vue";
import { getSetIdList, updateSet } from '../../api/setting/index'

let setFrom = ref({
  faceRecognitionSeconds: undefined, //人脸识别秒数
  unmannedScreenSeconds: undefined, //无人息屏秒数
  logoutSeconds: undefined,  //退出登录秒数
  attendansetFromce: undefined,
  switchValue: undefined,
});

//重置
function setFormRest() {
  setFrom.value.id = undefined;
  setFrom.value.title = undefined;
  setFrom.value.file = [];
  setFrom.value.createName = JSON.parse(localStorage.getItem("userInfo")).fullName,
    setFrom.value.orgId = JSON.parse(localStorage.getItem("userInfo")).orgId;
  setFrom.value.status = 0;
  setFrom.value.updateTime = undefined;
  setFrom.value.fileList = [];
}

const handleChange = (value) => {
  console.log(value);
};

// 管理考勤应用选择
const optionAttendance = [
  {
    value: 0,
    label: "项目管理人员考勤",
  },
  {
    value: 1,
    label: "安全管理人员考勤",
  },
  {
    value: 2,
    label: "工人考勤",
  },
];

// 点击保存
const submitSave = () => {
  updateSet(setFrom.value).then(res => {
    setFormRest()
    ElMessage.closeAll();
    if (res.data.code == 200) {
      ElMessage({
        message: '保存成功',
        type: 'success',
      })
      getList();
    } else {
      ElMessage({
        message: '保存失败',
        type: 'error',
      })
      getList();
    }
  })
};

//获取系统设置进行刷新列表
function getList() {

  getSetIdList('1').then(({ data }) => {
    console.log(data, '1222222');
    if (data.code == 200) {
      setFrom.value = data.data
    }
  })
}

onMounted(() => {
  getList()
})

</script>

<style lang="less" scoped>
.el-form {
  margin-top: 30px;

  .el-input-number {
    width: 60px;
    margin-right: 10px;
  }

  .el-select {
    width: 180px;
  }

  .el-button {
    margin-top: 60px;
  }
}

:deep(.el-input-number span) {
  display: none;
  width: 0;
}

:deep(.el-input-number .el-input__wrapper) {
  padding: 0;
}</style>